package com.cfjjc.gz.common.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * Utility methods for reading configuration (properties) file.
 */
public class ConfigUtil {

	private static Properties prop = new Properties();

	private static String dbType;

	private static String putIP;

	private static int putPort;

	private static String getIP;

	private static int getPort;

	private static String batchIP;

	private static int batchPort;

	private static String authIP;

	private static int authPort;
        
        private static String expPath;

	static {
		try {
			// 构造输入流读取otsconf.properties文件
			InputStream in = ConfigUtil.class.getClassLoader().getResourceAsStream("otsconf.properties");
			prop.load(in);

			String url = prop.getProperty("jdbc.url");
			if (url.contains("mysql")) {
				dbType = "MYSQL";
			} else if (url.contains("oracle")) {
				dbType = "ORACLE";
			} else if (url.contains("db2")) {
				dbType = "DB2";
			} else if (url.contains("mssql")) {
				dbType = "MSSQL";
			} else {
				throw new IllegalArgumentException("Unknow database type.");
			}

			String putUrl = prop.getProperty("socket.putUrl");
			System.out.println("putUrl: " + putUrl);
			String[] putArr = putUrl.split("\\:");
			putIP = putArr[0];
			putPort = new Integer(putArr[1]);

			String getUrl = prop.getProperty("socket.getUrl");
			System.out.println("getUrl: " + getUrl);
			String[] getArr = getUrl.split("\\:");
			getIP = getArr[0];
			getPort = new Integer(getArr[1]);

			String batchUrl = prop.getProperty("socket.batchUrl");
			System.out.println("batchUrl: " + batchUrl);
			String[] batchArr = batchUrl.split("\\:");
			batchIP = batchArr[0];
			batchPort = new Integer(batchArr[1]);

			String authUrl = prop.getProperty("socket.authUrl");
			System.out.println("authUrl: " + authUrl);
			String[] authArr = authUrl.split("\\:");
			authIP = authArr[0];
			authPort = new Integer(authArr[1]);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Properties getProp() {
		return prop;
	}

	public static String getDbType() {
		return dbType;
	}

	public static String getPutIP() {
		return putIP;
	}

	public static int getPutPort() {
		return putPort;
	}

	public static String getGetIP() {
		return getIP;
	}

	public static int getGetPort() {
		return getPort;
	}

	public static String getBatchIP() {
		return batchIP;
	}

	public static int getBatchPort() {
		return batchPort;
	}

	public static String getAuthIP() {
		return authIP;
	}

	public static int getAuthPort() {
		return authPort;
	}

	public static void main(String[] args) {

	}
}
